﻿#pragma once

#include <QString>
#include <QJsonValue>
#include <QJsonObject>
#include <QDateTime>
#include "except.hpp"

namespace cloud
{

struct Info
{
    Info() = default;

    Info& deserialize(const QJsonValue& val)
    {
        if (!val.isObject())
            THROW("json data error, is not a object");

        QJsonObject obj = val.toObject();

        _fname = obj["fpath"].toString();
        _fsize = obj["fsize"].toInt();
        _ishot = obj["ishot"].toBool();
        _mtime = QDateTime::fromSecsSinceEpoch(obj["mtime"].toInt())
                    .toString("yyyy-MM-dd hh:mm:ss");

        return *this;
    }

    QString _fname;
    int     _fsize;
    bool    _ishot;
    QString _mtime;
};

}
